home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-19 / iritsm3s.zip / CAGDRULD.C < prev    next >
C/C++ Source or Header  |  1991-12-01  |  3KB  |  93 lines

  1. /******************************************************************************
  2. * CagdRuld.c - Ruled srf operator out of given two profiles.              *
  3. *******************************************************************************
  4. * Written by Gershon Elber, May. 91.                          *
  5. ******************************************************************************/
  6.  
  7. #ifdef __MSDOS__
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <alloc.h>
  11. #endif /* __MSDOS__ */
  12.  
  13. #include "cagd_loc.h"
  14.  
  15. /******************************************************************************
  16. * Constructs a ruled surface between the two provided curves. The two curves  *
  17. * must have the same number of points, same curve type and same point type.   *
  18. * OtherOrder and OtherLen (equal for Bezier) specifies teh desired order and  *
  19. * refineness level (if Bspline) of the other ruled direction.              *
  20. ******************************************************************************/
  21. CagdSrfStruct *CagdRuledSrf(CagdCrvStruct *Crv1, CagdCrvStruct *Crv2,
  22.                 int OtherOrder, int OtherLen)
  23. {
  24.     CagdSrfStruct *Srf;
  25.     int i, j, k, MaxCoord, Len;
  26.     CagdPointType PType;
  27.     CagdBType IsNotRational;
  28.     CagdRType **SrfPoints, *Crv1SrcPt, *Crv2SrcPt, *SrfDestPt, t, t1,
  29.                          **Crv1Points, **Crv2Points;
  30.  
  31.     Crv1 = CagdCrvCopy( Crv1 );
  32.     Crv2 = CagdCrvCopy( Crv2 );
  33.  
  34.     CagdMakeCrvsCompatible(&Crv1, &Crv2, TRUE, TRUE );
  35.  
  36.     MaxCoord = CAGD_NUM_OF_PT_COORD(Crv1 -> PType),
  37.     Len = Crv1 -> Length;
  38.     PType = Crv1 -> PType;
  39.     IsNotRational = !CAGD_IS_RATIONAL_CRV(Crv1);
  40.     Crv1Points = Crv1 -> Points,
  41.     Crv2Points = Crv2 -> Points;
  42.  
  43.     switch (Crv1 -> GType) {
  44.     case CAGD_CBEZIER_TYPE:
  45.         Srf = BzrSrfNew(Len, OtherLen, PType);
  46.         break;
  47.     case CAGD_CBSPLINE_TYPE:
  48.         Srf = BspSrfNew(Len, OtherLen, Crv1 -> Order, OtherOrder, PType);
  49.         GEN_COPY(Srf -> UKnotVector, Crv1 -> KnotVector, sizeof(CagdRType) *
  50.                             (Len + Crv1 -> Order));
  51.         BspKnotUniformOpen(OtherLen, OtherOrder, Srf -> VKnotVector);
  52.         break;
  53.     case CAGD_CPOWER_TYPE:
  54.         FATAL_ERROR(CAGD_ERR_POWER_NO_SUPPORT);
  55.         return NULL;
  56.     default:
  57.         FATAL_ERROR(CAGD_ERR_UNDEF_CRV);
  58.         return NULL;
  59.     }
  60.  
  61.     /* Copy the control mesh - first row is exactly the same as the first    */
  62.     /* curve while last row is the same as second curve.             */
  63.     /* The middle rows are convex blend of the first/last rows.             */
  64.     SrfPoints = Srf -> Points;
  65.  
  66.     for (i = IsNotRational; i <= MaxCoord; i++)               /* First row. */
  67.     GEN_COPY(SrfPoints[i], Crv1Points[i],
  68.          sizeof(CagdRType) * Len);
  69.  
  70.     /* Make a copy of the last row. */
  71.     for (i = IsNotRational; i <= MaxCoord; i++)                /* Last row. */
  72.     GEN_COPY(&SrfPoints[i][Len * (OtherLen - 1)], Crv2Points[i],
  73.          sizeof(CagdRType) * Len);
  74.  
  75.     /* And compute the internal rows, if any: */
  76.     for (j = 1; j < OtherLen - 1; j++) {
  77.     t = ((CagdRType) j) / (OtherLen - 1);
  78.     t1 = 1.0 - t;
  79.     for (i = IsNotRational; i <= MaxCoord; i++) {
  80.         SrfDestPt = &SrfPoints[i][Len * j];
  81.         Crv1SrcPt = Crv1Points[i];
  82.         Crv2SrcPt = Crv2Points[i];
  83.         for (k = 0; k < Len; k++)
  84.         SrfDestPt[k] = t1 * Crv1SrcPt[k] + t * Crv2SrcPt[k];
  85.     }
  86.     }        
  87.  
  88.     CagdCrvFree( Crv1 );
  89.     CagdCrvFree( Crv2 );
  90.  
  91.     return Srf;
  92. }
  93.